package com.bw.workdemo.service;

import com.bw.workdemo.mapper.TbRegisterMapper;
import com.bw.workdemo.pojo.TbRegister;
import excel.ImportRspInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@Service
public class TbRegisterServiceImpl implements  TbRegisterService {
    @Autowired
    TbRegisterMapper tbRegisterMapper;

    @Override
    public boolean addAll(ImportRspInfo<TbRegister> list) {
        List<TbRegister> data = list.getData();
        data.forEach(d->{
            tbRegisterMapper.insert(d);
        });
        return true;
    }


   @Override
    public Object findByDateL(List<String> dateStrs) {
        List arr = new ArrayList();
        for(int i=0;i<7;i++){
            int couter = tbRegisterMapper.selectByDateL(dateStrs.get(i));
            arr.add(couter);
        }
        return arr;
    }

    @Override
    public Object findByDateP(List<String> dateStrs) {
        Calendar calendar = Calendar.getInstance();
        List arr = new ArrayList();
        for(int i=0;i<7;i++){
            calendar.add(Calendar.DATE,-1);
            int couter = tbRegisterMapper.selectByDateP(dateStrs.get(i));
            arr.add(couter);
        }

        return arr;
    }

    @Override
    public Object findByDateA(List<String> dateStrs) {
        Calendar calendar = Calendar.getInstance();
        List arr = new ArrayList();
        for(int i=0;i<dateStrs.size();i++){
            int couter = tbRegisterMapper.selectByDateA(dateStrs.get(i));
            arr.add(couter);
        }

        return arr;
    }

    @Override
    public Object findBySex() {
        return tbRegisterMapper.selectBySex();
    }

    @Override
    public List selectList() {
        return tbRegisterMapper.selectList();
    }
}

